import axios from 'axios';
import { Message } from 'element-ui';

axios.interceptors.response.use(
  response => {
    if (response.config.url === 'https://restapi.amap.com/v3/config/district') {
      return response;
    }
    if (response && response.data && response.data.status !== 0) {
      Message({
        showClose: true,
        message: response.data.msg,
        type: 'warning'
      });
    }
    return response;
  },
  err => {
    Message({
      showClose: true,
      message: `ajax请求失败: ${err.message}`,
      type: 'error'
    });
  }
);

function request(option) {
  return axios(option);
}

export default request;
